Skip to content

[WIP] Remove database usage from push notification extension #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 39 commits into
base: dev
Choose a base branch
from

Conversation

mpretty-cyro
Copy link
Collaborator

The iOS app has had a long standing crash related to the database, the app crashes with the error code 0xdead10cc (or “Deadlock”) and it happens when the app goes into a “suspended” state whilst it still maintains a lock on the database. We've tried a number of times to resolve this issue without a large structural change but, while we seem to have reduced the frequency, we've been unable to entirely resolve it.

Since we have exhausted all other options the goal now is to move the database file (and any other app data) from the “AppGroup” into the main app directory where the OS will no longer need to put a lock on the file, and as a result the 0xdead10cc should no longer be possible.

The purpose of this PR is to update the Push Notification Extension to function without needing access to the database (the first step needed to relocate the app files).

mpretty-cyro and others added 3 commits May 12, 2025 14:36
• Updated the General cache to include the users seckey (rather than fetching it from the DB every time causing unneeded load)
• Updated a bunch of Crypto usage to no longer need a `db` or `dependencies` instance passed to it
• Added unit tests for General.Cache
• Replaced `Identity.userExists` with `General.Cache.userExists` (no need for database access anymore)
• Moved the SwarmPoller message handling logic into it's own function to make debugging stack traces a little easier
• Cleaned up some hard-to-read logic
DBR - 1 - Cached seckey, cleaned up crypto usage
@mpretty-cyro mpretty-cyro self-assigned this May 13, 2025
@mpretty-cyro mpretty-cyro added enhancement New feature or request Jira This ticket is being tracked in Jira labels May 13, 2025
mpretty-cyro and others added 24 commits May 13, 2025 14:03
• Added the new MessageDeduplication table
• Added a migration to populate the MessageDeduplication table
• Added ExtensionHelper functions to store records in the AppGroup for deduplication purposes
• Updated the logic to use MessageDeduplication table & files for deduplication purposes
• Refactored message parsing to not rely on the database
• Refactored message deduplication to not rely on the database in the PN extension
• Removed the old ControlMessageProcessRecord table
…receiving-process

DBR - 2 - Refactored the message deduplication logic
• Updated the General cache to include the users seckey (rather than fetching it from the DB every time causing unneeded load)
• Updated a bunch of Crypto usage to no longer need a `db` or `dependencies` instance passed to it
• Added unit tests for General.Cache
• Replaced `Identity.userExists` with `General.Cache.userExists` (no need for database access anymore)
• Moved the SwarmPoller message handling logic into it's own function to make debugging stack traces a little easier
• Cleaned up some hard-to-read logic
…message-notification

DBR - 3 - Initial notification extension refactoring, handling visible message PNs
• Added the new MessageDeduplication table
• Added a migration to populate the MessageDeduplication table
• Added ExtensionHelper functions to store records in the AppGroup for deduplication purposes
• Updated the logic to use MessageDeduplication table & files for deduplication purposes
• Refactored message parsing to not rely on the database
• Refactored message deduplication to not rely on the database in the PN extension
• Removed the old ControlMessageProcessRecord table
• Added code to write user metadata to disk
• Added code to write config dumps to disk
• Added code to write push notification messages to disk
• Added code to read push notification messages from disk on launch
• Added code to calculate the unread count in the PN extension (based on the last known main app unread count)
• Added code to replicate config dumps to the AppGroup for extensions to load
• Added async/await read & write functions to Storage
• Tweaked the logic when the user taps on a notification to wait until after the PN extension message files have been loaded (with a 3s timeout)
• Fixed an issue where notifications were being overwritten in all cases (now using the serverHash as the identifier when available)
• Added unit tests for new ExtensionHelper functions
• Tweaked the `#file` variables to use `#fileID` instead (relative to project dir)
• Updated AppDelegate so it doesn't run when running unit tests (could slow other stuff down or cause bugs)
• Fixed broken unit tests
• Fixed an issue where the notification extension wasn't correctly reporting the successful handling of a push notification
Ryan ZHAO and others added 12 commits May 20, 2025 14:13
…ving-to-disk

DBR - 4 - Saving and reading messages from disk
# Conflicts:
#	Session.xcodeproj/project.pbxproj
# Conflicts:
#	Session.xcodeproj/project.pbxproj
#	SessionMessagingKit/Open Groups/OpenGroupManager.swift
#	SessionMessagingKit/Sending & Receiving/Notifications/NotificationsProtocol.swift
#	SessionMessagingKit/Sending & Receiving/Notifications/Types/NotificationCategory.swift
#	SessionMessagingKitTests/_TestUtilities/CommonSMKMockExtensions.swift
#	SessionMessagingKitTests/_TestUtilities/MockNotificationsManager.swift
#	SessionNotificationServiceExtension/NSENotificationPresenter.swift
#	SessionUtilitiesKit/General/SessionId.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Jira This ticket is being tracked in Jira
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant